import java.util.Arrays;
import java.util.Random;

/**
 * @author: gao
 * @create-date: 2025/5/30 21:26
 */

public class Main {
    public static void main(String[] args) {
        int[] nums = new int[6];
        DisOrder(nums);
        System.out.println("排序前：" + Arrays.toString(nums));
        BubbleSort(nums);
        System.out.println("排序后：" + Arrays.toString(nums));
    }

    public static void DisOrder(int[] nums) {
        Random ran = new Random();
        for (int i = 0; i < nums.length; i++) {
            nums[i] = ran.nextInt(100);
        }
    }

    public static void BubbleSort(int[] nums) {
        for (int i = 0; i < nums.length - 1; i++) {
            for (int j = 0; j < nums.length - 1 -i; j++) {
                if (nums[j] > nums[j + 1]) {
                    swap(nums,j,j + 1);
                }
            }
        }
    }

    public static void swap (int[] nums,int i ,int j) {
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }
}